
stringify = function (obj) {
	var str = "";
	for (var prop in obj) {
		str += prop + "=" + obj[prop] + " ";
	}
	return str;
};


if (this.load) {
	load("cloud.js");
	var console = {
			log: function (msg) {
				print (msg);
			}
	};
}


/***********************************************/ 
Cloud.start();
var DATA_NODES = 2;
var sw = Cloud.newSwitch(DATA_NODES + 2, 100e6);

// namenode 
var namenode = Cloud.newHost();
Cloud.connect(namenode, sw, 0);
nnapp = namenode.addApplication(Namenode, namenode);

// datanodes
for (var i = 0; i < DATA_NODES; i ++) {
	var host = Cloud.newHost();
	Cloud.connect(host, sw, i + 2);
	host.addApplication(Datanode, host, namenode.ip);
}

// client
var client = Cloud.newHost();
Cloud.connect(client, sw, 1);
var app = client.addApplication(Client, client, namenode.ip);

// write file
client.setTimer(5).done(function () {
	this.createFile("/file1", [], 2, 64e6, function (file) {
		app.log("writing data to client");
		file.write(6 * PACKET_SIZE);
	});
}, app);

nnapp.setTimer(6).done(nnapp.print, nnapp, print);

Cloud.setLogger(function (msg) {
	console.log(msg);
});
Cloud.simulate(10);
